package com.versita.utils;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;

import com.versita.domain.User;

public class ExternalAPI {
    EntityManager em = ShadowEntityManager.getEntityManager();

    /**
     * -1 not found
     * else the hash of the id
     * @return
     */
    public void listUsers() {
        Map<String,Object> map = em.getProperties();
        List<User> users = em.createQuery("select user from User user").getResultList();
        for (Iterator<User> i=users.iterator(); i.hasNext();) {
            User user = i.next();
            System.out.println(user);
        }
    }

    public void findUser() {
        User user = em.find(User.class, new Long(1));
        System.out.println(user);
    }

    public static void main(String[] args) {
        ExternalAPI eapi = new ExternalAPI();
        eapi.findUser();
        System.out.println("-------");
        eapi.listUsers();
        System.out.println("-------");
    }
}
